<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>匀速运动</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 500px;
            height: 500px;
            position: relative;
            border-right: 10px solid pink;
        }
        .move{
            width: 100px;
            height: 100px;
            background: skyblue;
            position: absolute;
            left: 0;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="move"></div>
    </div>

    <script>
        // 获取元素
        var move = document.querySelector('.move');

        // 初始化位移
        let left = 0;

        let timer = setInterval(()=>{
            left += 10;

            if(left>=400){
                left = 400;
                clearInterval(timer);
            }

            move.style.left = left + 'px';
        },100)
    </script>
</body>
</html>